/**
 * Class: Chord
 *
 * Purpose: 
 *
 * Created: Jan 30, 2010 @ 5:59:49 PM
 * @author Ken Scott
 */
package org.openfantasia.musica.events;

import org.openfantasia.musica.Musica;
import org.openfantasia.musica.Scale;
import org.openfantasia.musica.instruments.Instrument;

import java.util.List;

public class Chord extends EventList {

	public Chord() {
	}


	public Chord(Musica mc) {
		super(mc);
	}


	public Chord(Musica mc, Scale scale, Instrument instrument, double volume, int duration) {
		this(mc, scale, 0, 0, instrument, volume, duration);
	}


	public Chord(Musica mc, Scale scale, int offset, Instrument instrument, double volume, int duration) {
		this(mc, scale, offset, 0, instrument, volume, duration);
	}


	public Chord(Musica mc, Scale scale, int offset, int count, Instrument instrument, double volume, int duration) {
		super(mc);

		if (count == 0) {
			count = Integer.MAX_VALUE / 2;		// '0' means 'ignore this
		}

		setName("Chord: " + instrument.getName() + " " + scale.getName() + " offset " + offset + " tones; " + Musica.getNoteDurationName(duration) + " @ vol " + volume);
		for (int i = offset; (i < (offset + count)) && (i < scale.getToneFrequencies().size()); i++) {
			double freq = scale.getToneFrequencies().get(i);
			add(new Note(mc, instrument, freq, volume, duration), 0);
		}
		this.duration = duration;
	}


	public Chord(Chord that) {
		copy(that);
	}


	public void copy(Chord that) {
		super.copy(that);
	}


	public Chord copy() {
		return new Chord(this);
	}


	public void action() {
		List<Event> events = getEvents(0);
		if (events != null) {
			for (Event event : events) {
				event.action();
			}
		}
	}
}
